* 02_an_acts is called by main to produce results
*-------------------------------------------------------------------------------
* PREPARE ANNUAL SERIES FOR ANALYSIS 
*-------------------------------------------------------------------------------		
	
	* Scientization (see `cr_ivs' for indicators)
	
		sort year
		gen l_scientization = scientization[_n-1]
		
		
					
	* Transform proportions to percentages (%)
	
		global props uk_suffrage wst_int_cnflct
		
		foreach var in $props {
			replace `var' = `var' * 100
		}
			
			
			
	* Generate and lag growth vars
	
		global IVS	fb_ind fb_ag l_fb_ag ///
					uk_suffrage  ///
					uk_lifeex ///
					imp_uk_sch_enrll 
					

		sort year
		foreach var in $IVS {
			cap drop l_`var'
			gen l_`var' = `var'[_n-1]
			cap drop gr_`var'
			gen gr_`var' = 100*(l_`var' - l_`var'[_n-1]) / l_`var'[_n-1]
		}
		
		
		
	* Lag conflict vars
	
		global CNFLCT 	uk_dmst_cnflct ///
						uk_int_cnflct ///
						wst_int_cnflct 
					
					
		foreach var in $CNFLCT {
			cap drop l_`var'
			gen l_`var' = `var'[_n-1]
		}
	
	
	
	* Time variable
		
		gen y1833 = 1 if year >= 1833
		recode y1833 . = 0 

		

	* Development indicator 
		alpha  l_uk_lifeex  l_fb_ag  l_uk_suffrage , std 
		factor l_uk_lifeex  l_fb_ag  l_uk_suffrage ,  ipf
		cap drop l_dev
		predict l_dev
		label var l_dev "l_dev"		
			
	
	
	* Nation-state model vars
	
		global DIM1			wst_indpndnt ///
							wst_ctznshp ///
							wst_suffrage ///
							wst_anthem ///
							wst_flag ///
							wst_bank ///
							imp_wst_sch_enrll
							
							
							
	* Factor analysis of dimension 1
	
		alpha	$DIM1, std item
		pca	$DIM1
		cap drop DIM1
		predict DIM1 
		
		sort year
		cap drop l_DIM1
		gen l_DIM1= DIM1[_n-1]
		
				
		
	* Factor analysis of composite model 
	
		global NATION_STATE l_DIM1 ///
							scientization 
							
		alpha $NATION_STATE, std item
		pca	$NATION_STATE
		cap drop nation_state
		predict nation_state
		
		sort year
		cap drop l_nation_state
		gen l_nation_state= nation_state[_n-1]

		
		
		
*-------------------------------------------------------------------------------
* MERGE IN ACTS DATA
*-------------------------------------------------------------------------------

	* Merge in per-year n acts about schooling
	* DF: 1 row = 1 year
	
		merge m:1 year using "${DV}sch_nyr.dta"
		drop _merge
		
		gen l_sch_nyr = sch_nyr[_n-1]

		
		
	* All acts in all years
	* DF: 1 rwo = 1 act
	
		merge 1:m year using "${DV}sch_acts.dta"
		cap drop _merge

		egen yr_tag = tag(year)

		
	
	
*-------------------------------------------------------------------------------
* Table 1 - Main findings showing impact of scientization
*-------------------------------------------------------------------------------
	

		global xls  "${VZ}00_text/table_1.xls"
		global txt	"${VZ}00_text/table_1.txt"
		cap erase 	"${xls}"
		cap erase	"${txt}"
		global model_opts    	vce(cluster year) nolog 
		global outreg_opts		, excel ///
								dec(3) ///
								eform cti(odds ratio) label  ///
								addstat(Log Likelihood, e(ll), ///
										Pseudo R-Squared, e(r2_p)) ///		


		
		global M1			logistic 	sch ///	
										l_scientization ///
										y1833  ///
										l_sch_nyr  
										
									
		global M2			$M1 ///
								l_uk_int_cnflct ///
								l_wst_int_cnflct 
							  
			
							
		outreg2 using "${xls}" $outreg_opts : ///
								$M1 ///
									, $model_opts
								
									
		outreg2 using "${xls}" $outreg_opts : ///
								$M2 ///
									, $model_opts
								
								
		outreg2 using "${xls}" $outreg_opts : ///
								$M2 ///
									l_uk_lifeex  ///
									, $model_opts								
								
												
		outreg2 using "${xls}" $outreg_opts append: ///
								$M2 ///
									l_fb_ag    ///
									, $model_opts
										
										
		outreg2 using "${xls}" $outreg_opts append: ///
								$M2 ///
									l_uk_suffrage  ///
									, $model_opts
										
										
		outreg2 using "${xls}" $outreg_opts append: ///
								$M2 ///
									l_dev  ///
									, $model_opts
								
								
		
		* Compute R2 and BIC: these are inserted by hand
		
			$M1 ///
			, $model_opts
			fitstat
				
			$M2 ///
			, $model_opts
			fitstat
			
			$M2 ///
			l_uk_lifeex  ///
			, $model_opts			
			fitstat
			
			$M2 ///
			l_fb_ag    ///
			, $model_opts
			fitstat

			$M2 ///
			l_uk_suffrage  ///
			, $model_opts
			fitstat
					
			$M2 ///
			l_dev  ///
			, $model_opts
			fitstat

								
								
*-------------------------------------------------------------------------------
* Table 2 - Exploring a more comprehensive nation-state model
*-------------------------------------------------------------------------------

		global xls  "${VZ}00_text/table_2.xls"
		global txt	"${VZ}00_text/table_2.txt"
		cap erase 	"${xls}"
		cap erase	"${txt}"
		global model_opts   	vce(cluster year) nolog 
		global outreg_opts		, excel ///
								dec(3) ///
								eform cti(odds ratio) label  ///
								addstat(Log Likelihood, e(ll), ///
										Pseudo R-Squared, e(r2_p)) ///		

			
		

		
		global M1			logistic 	sch ///	
										l_nation_state ///
										y1833 ///
										l_sch_nyr 
										
									
		global M2			$M1 ///
								l_uk_int_cnflct ///
								l_wst_int_cnflct 
							  
			
							
		outreg2 using "${xls}" $outreg_opts : ///
								$M1 ///
									, $model_opts
								
									
		outreg2 using "${xls}" $outreg_opts : ///
								$M2 ///
									, $model_opts
								
								
		outreg2 using "${xls}" $outreg_opts : ///
								$M2 ///
									l_uk_lifeex  ///
									, $model_opts								
								
												
		outreg2 using "${xls}" $outreg_opts append: ///
								$M2 ///
									l_fb_ag    ///
									, $model_opts
										
										
		outreg2 using "${xls}" $outreg_opts append: ///
								$M2 ///
									l_uk_suffrage  ///
									, $model_opts
										
										
		outreg2 using "${xls}" $outreg_opts append: ///
								$M2 ///
									l_dev  ///
									, $model_opts
									

		* Compute R2 and BIC: these are inserted by hand
		
			$M1 ///
			, $model_opts
			fitstat
				
			$M2 ///
			, $model_opts
			fitstat
			
			$M2 ///
			l_uk_lifeex  ///
			, $model_opts			
			fitstat
			
			$M2 ///
			l_fb_ag    ///
			, $model_opts
			fitstat

			$M2 ///
			l_uk_suffrage  ///
			, $model_opts
			fitstat
					
			$M2 ///
			l_dev  ///
			, $model_opts
			fitstat
			
